/**
 * @param {number} capacity
 */
 var LRUCache = function (capacity) {
    this.len = capacity
    this.tempMap = new Map()
};

/** 
 * @param {number} key
 * @return {number}
 */
LRUCache.prototype.get = function (key) {
    if (this.tempMap.has(key)) {
        let result = this.tempMap.get(key)
        this.tempMap.delete(key)
        this.tempMap.set(key, result)
        return result
    } else {
        return -1
    }
};

/** 
 * @param {number} key 
 * @param {number} value
 * @return {void}
 */
LRUCache.prototype.put = function (key, value) {
    // let temparr = [...this.tempMap.keys()]
    // if (temparr.length >= this.len) {
    //     this.tempMap.delete(temparr[0])
    // }
    // this.tempMap.set(key, value)

    let temparr = []
    if (this.tempMap.has(key)) {
        this.tempMap.delete(key)
    } 
    this.tempMap.set(key, value)
    temparr=[...this.tempMap.keys()]
    if (temparr.length > this.len) {
        this.tempMap.delete(temparr[0])
    }
};

let aaa = new LRUCache(2);
// aaa.get(2)
// aaa.put(2,6)
// aaa.get(1)
// aaa.put(1,5)
// aaa.put(1,2)
// aaa.get(1)
// aaa.get(2)


aaa.put(1,1)
aaa.put(2,2)
aaa.get(1)
aaa.put(3,3)
aaa.get(2)
aaa.put(4,4)
aaa.get(1)
aaa.get(3)
aaa.get(4)
console.log(aaa.tempMap)